<!--
 * @Author: duchengdong
 * @Date: 2021-12-24 13:46:21
 * @LastEditors: duchengdong
 * @LastEditTime: 2022-01-06 11:41:44
 * @Description: 
-->
<template>
	<view class="login">
		<!-- <g-cell-datepicker 
			v-model="dateValue"
			selectTitle="选择提醒时间"
			label="第一次时间"
			mode="date"
			formatter="YYYY-MM-DD"
		></g-cell-datepicker> -->
		<g-cell-datepicker
			v-model="dateValue"
			selectTitle="选择提醒时间"
			label="第一次时间"
			mode="time"
			formatter="hh:mm"
			:filter="filterHandle"
		></g-cell-datepicker>
		<g-cell-check class="userinfo-cell" label="性别" v-model="genderCode" :activeValue="2" :inactiveValue="1" type="switch"></g-cell-check>
		<g-cell-picker
			class="userinfo-cell"
			label="与患者关系"
			placeholder="请选择"
			selectTitle="选择患者关系"
			v-model="relationship"
			:selectList="columnsShip"
		></g-cell-picker>
		<g-cell-text class="userinfo-cell" label="姓名" v-model="patientName" :disabled="true" placeholder="请输入"></g-cell-text>
		<g-not-data text="你还没有主诊医生" v-if="true"></g-not-data>
		<g-cell-input-unit
			class="userinfo-cell"
			label="单次用量"
			v-model="num"
			:unit="unit"
			:disabled="false"
			:selectList="unitList"
			@changeUnit="changeUnitHandle"
			placeholder="请输入"
		></g-cell-input-unit>
		<g-calendar
			@close="close"
			@change="changeDate"
			@changeMonth="changeMonth"
			:selected="selected"
			:checkedDate="checkedDate"
			:endDate="endDate"
			v-if="isShow"
		></g-calendar>
		<button @click="clickHandle">订阅</button>
		<blood-circle :chartData="chartData"></blood-circle>
	</view>
</template>
<script>
import subscribeMessage from '@/utils/mixins/subscribeMessage'
import bloodCircle from './components/blood-circle.vue'
export default {
	components: {bloodCircle},
	mixins: [subscribeMessage],
	data() {
		return {
			isCheck: false,
			dateValue: '',
			genderCode: 2,
			relationship: '',
			columnsShip: [
				[
					{
						id: 0,
						label: '患者本人',
					},
					{
						id: 1,
						label: '患者家属',
					},
				],
			],
			patientName: 'abc',
			num: '',
			unit: 0,
			unitList: [
				[
					{
						id: 0,
						label: '片',
					},
					{
						id: 1,
						label: '粒',
					},
					{
						id: 2,
						label: '颗',
					},
				],
			],
			selected: [],
			checkedDate: '2021-12-27',
			endDate: new Date(),
			currentTime: new Date(),
			isShow: true,
			chartData: {
				bloodSugarNum: 20,
				code: 11,
			},
		}
	},
	watch: {
		genderCode(v) {
			console.log(v)
		},
	},
	mounted() {
		setTimeout(() => {
			// this.genderCode = 1
			this.chartData = {
				bloodSugarNum: 6.9,
				code: 11,
			}
		}, 100)
	},
	methods: {
		filterHandle(type, values) {
			if (type == 'minute') {
				return values.filter((v, i) => i % 30 == 0)
			}
			return values
		},
		changeUnitHandle(v) {
			this.unit = v
		},
		close() {
			// 关闭日历
			this.isShow = false
		},
		changeDate(e) {
			//点击日历日期
			if (e.fullDate != this.$date.formatDate(this.currentTime)) {
				this.clearAll()
			}
			this.currentTime = new Date(e.fullDate)
			this.checkedDate = e.fullDate
			// this.getInitData(e.fullDate)
		},
		changeMonth(time) {
			//改变日历月份
			let year = time.split('-')[0]
			let month = time.split('-')[1]
			// this.getFlagData(year, month)
		},
		getFlagData(year, month) {
			//获取日历已记录的日期
			getSignInData(year, month)
				.then(res => {
					this.selected = res.data
				})
				.catch(err => {})
		},
		async clickHandle() {
			let res = await this.subscribeHandle()
			console.log(res)
		},
	},
}
</script>
<style lang="scss" scoped></style>
